<div class="span-18" id="project_detail">
  <div class="section span-18" id="project">
    <%= render :partial => "show", :locals => {:project => @project} %>
  </div>

  <div class="section" id="budget" style="">
    <h2>Payment Schedule</h2>
    <table class="tasks">
      <thead>
        <tr>
          <th>#</th>
          <th>Due</th>
          <th>Amount</th>
          <th>Received</th>
          <th></th>
        </tr>
      </thead>
      <tbody id="project_payments">
        <% @project.payments.each_with_index do |payment,i| %>
          <tr id="payment_<%= payment.id %>">
            <td><%= payment.id %></td>
            <td><%= payment.due_on.to_s(:long) %></td>
            <td><%= "#{currency_format(payment.amount)}" %></td>
            <td><%= payment.received_on.blank? ? "<span class=\"quiet\">not yet!</span>" : payment.received_on.to_s(:long) %></td>
            <td class="actions">
              <%= link_to_remote "Edit", :update => "payment_form_row", :url => show_remote_form_admin_project_payment_url(@project, payment), :method => :get, :html => { :class  => "task_action", :onclick => "$j('#payment_#{payment.id} td').addClass('highlight')" } %> | 
              <%= link_to_remote 'Delete', :url => admin_payment_url(payment.id), :method => :delete, :confirm => "Are you sure?", :html => {:class  => "task_action"} %>
            </td>
          </tr>
        <% end %>
      </tbody>
      <tbody>
        <tr class="table_bottom">
          <th colspan="4"></th>
          <th><%=link_to_remote "New", :update => "payment_form_row" , :url => show_remote_form_admin_project_payment_url(@project, "new"), :method => :get, :html => { :class  => "task_action" } %></th>
        </tr>
      </tbody>
      <tbody id="payment_form_row"></tbody>
    </table>
  </div>

  <div class="section span-18" id="milestones">
    <h2>Milestones</h2>
    <% if @project.milestones.blank? %>
      <p class="quiet" id="no_milestones">None yet.</p>
    <% else %>    
      <% @project.milestones.each do |milestone| %>
        <div id="milestone_<%= milestone.id %>" class="section">
          <%= render :partial => "admin/milestones/show", :locals => {:milestone => milestone} %>
        </div>
      <% end %>
    <% end %>
    <div id="new_milestone"></div>
    
    <div class="span-18 clear" id="new_milestone_action">
      <p><%= link_to_remote "#{@project.milestones.blank? ? "Create a new" : "Add another"} milestone", :update => "new_milestone", :url => show_remote_form_admin_project_milestone_url(@project, "new"), :method => :get, :html => {:onclick => "$j('#no_milestones').hide();"} %></p>
    </div>
  </div>
  
</div>

<div class="span-6 last" id="project_links">
  <ul>
    <li><%= link_to "Public View", "" %></li>
    <li><%= link_to "Client View", "" %></li>
  </ul>
</div>

<script type="text/javascript">
  var converter         = new Showdown.converter();
  
  function toggle_markdown_preview(text_area_id){
    var text_area_element = $j("#" + text_area_id);
    var preview_element   = $j("#preview_" + text_area_id);
    
    preview_element.slideToggle('fast', function() { 
      preview_element.toggleClass("hidden");
      if ( !preview_element.hasClass("hidden") ){
        preview_element.html(converter.makeHtml(text_area_element.val()));
      }
    });
  }

  function preview_markdown(text_area_id) {
    var text_area_element = $j("#" + text_area_id);
    var preview_element   = $j("#preview_" + text_area_id);

    preview_element.html(converter.makeHtml(text_area_element.val()));
  }
</script>